package com.web.netalbum.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CenterController extends HttpServlet {

	private static final long serialVersionUID = -4432243104107571790L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setHeader("Cache-Control", "no-cache");  
		response.setHeader("Pragma", "no-cache");  
		response.setDateHeader("Expires", 0);  
			String operator=request.getParameter("operator");
			System.out.println(operator);
			if(operator.equals("init")){
				String page=request.getParameter("page");
				System.out.println(page);
				if(page.equals("index")){
					String part=request.getParameter("part");
					System.out.println(part);
					if(part.equals("main")){
						WebUtil.initIndexBody(request, response);
					}else if(part.equals("categroy")){
						WebUtil.initIndexCategroy(request, response);
					}
				}
			}else if(operator.equals("register")){
				String type=request.getParameter("type");
				if(type.equals("check")){
					String value=request.getParameter("value");
					WebUtil.checkUserName(value,request, response);
				}else if(type.equals("submit")){
					String userName=request.getParameter("userName").trim();
					String email=request.getParameter("email").trim();
			//		System.out.println(email);
					String password=request.getParameter("password").trim();
					WebUtil.register(userName,email,password,request,response);
				}
			}else if(operator.equals("activeAccount")){
				String id = request.getParameter("id");
				String code=request.getParameter("code");
				WebUtil.activeCount(id,code,request,response);
			}else if(operator.equals("login")){
				String userName=request.getParameter("userName").trim();
				String password=request.getParameter("password").trim();
				System.out.println("login"+userName);
				WebUtil.login(userName,password,request,response);
			}else if(operator.equals("resetPassword")){
				String email=request.getParameter("email").trim();
				System.out.println("resetPassword"+" "+email);
				WebUtil.resetPassword(email,request,response);
			}else if(operator.equals("sendResetPassEmail")){
				String email=request.getParameter("email").trim();
				System.out.println("sendResetPassEmail"+" "+email);
				WebUtil.sendResetPassEmail(email,request, response);
			}else if(operator.equals("reset")){
				String id = request.getParameter("id");
				String code=request.getParameter("code");
				WebUtil.passReset(id,code,request,response);
			}else if(operator.equals("updatePassword")){
				String password=request.getParameter("password");
				String id=request.getParameter("id");
				System.out.println("updatePassword"+id);
				System.out.println("updatePassword"+password);
				WebUtil.updatePassword(id,password,request, response);
			}else if(operator.equals("search")){
				String key=request.getParameter("key");
				System.out.println("search "+key);
				WebUtil.search(key,request,response);
			}else if(operator.equals("categroy")){
				String albumId=request.getParameter("albumId");
				System.out.println("albumId "+albumId);
				WebUtil.album(albumId,request,response);
			}else if(operator.equals("paging")){ //分页
				String page=request.getParameter("page");
				String pageNum=request.getParameter("pageNum");
				System.out.println("paging "+page);
				System.out.println("paging "+pageNum);
				WebUtil.page(page,pageNum,request,response);
			}else if(operator.equals("single")){
				String photoId = request.getParameter("id");
				String num = request.getParameter("num");
				System.out.println("single "+photoId);
				WebUtil.single(photoId,num,request,response);
			}else if(operator.equals("singleInit")){
				String albumId=request.getParameter("albumId");
				String photoId=request.getParameter("photoId");
				System.out.println("singleInit "+albumId);
				System.out.println("singleInit "+photoId);
				WebUtil.singleInit(photoId,albumId,request,response);
			}else if(operator.equals("allImage")){
				WebUtil.initImages(request,response);
			}else if(operator.equals("left")){
				String num=request.getParameter("num");
				System.out.println("left "+num);
				WebUtil.left(num,request,response);
			}else if(operator.equals("right")){
				String num=request.getParameter("num");
				System.out.println("right "+num);
				WebUtil.right(num,request,response);
			}else if(operator.equals("personal")){
				String userName = request.getParameter("userName");
				System.out.println("personal "+userName);
				WebUtil.person(userName,request,response);
			}else if(operator.equals("person_init")){
				WebUtil.personInit(request,response);
			}else if(operator.equals("showAllPhotos")){
				String userName = request.getParameter("userName");
				WebUtil.showAllPhotos(userName,request,response);
			}
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
